Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to authenticate via client certificates #38

Conversation

ctenruh-phytec
Copy link
Contributor

@ctenruh-phytec ctenruh-phytec commented May 12, 2020

Client certificate is send to the set Server.
Also added a new condition in "get_key_string" since before the function would return TRUE when "val" was given an empty string.
Edited the "rauc-hawkbit-updater.t" file accordingly so the tests won't fail.

@ctenruh-phytec ctenruh-phytec changed the title Wip/ctenruh phytec/client certificates Add option to authenticate via client certificates May 12, 2020
@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch 2 times, most recently from c109fa7 to 93b0872 Compare May 13, 2020 13:41
@Raphexion
Copy link
Contributor

If you have time and if you find it appropriate, would you mind writing a a couple of lines about the client certificates in the README. We already have some text about the two different tokens. I think it could be helpful to new users of the updater.

@ctenruh-phytec
Copy link
Contributor Author

of course.

@Raphexion
Copy link
Contributor

@ctenruh-phytec Great work on the README 🥇

@ctenruh-phytec
Copy link
Contributor Author

thanks :)

@ejoerns ejoerns added the enhancement New feature or request label Jun 26, 2020
@bantu
Copy link

bantu commented Aug 21, 2020

Thank you for your work on this feature. I, too, would like to see this implemented. If client devices have TLS client certificates anyway, it seems like a good idea to use those. The primary benefit to me seems to be that, technically, the hawkbit server does not have to be aware of the client (e.g. know a client-specific auth token) before its first connection.

However, looking at this pull request, I am somewhat confused by the language used; within the patch and also within the pull request description. In particular, "Client certificate and private key of Client certificate are send to the set Server." confuses me. The client uses asymmetric cryptography and has a private/public key pair. The client certificate is essentially a signature of a certificate authority on the client public key. The client certificate contains no private information and must be sent to the server. However, the private key is used for decryption or signing only; and must never be transferred.

README.md Outdated Show resolved Hide resolved
@bantu
Copy link

bantu commented Aug 21, 2020

The implementation provides access to the certificate and private key to curl, so (under the assumption that curl behaves correctly) does not seem to actually send the private key to the server. So my comment merely refers to a documentation issue.

README.md Outdated Show resolved Hide resolved
@ctenruh-phytec
Copy link
Contributor Author

ctenruh-phytec commented Aug 24, 2020

Hello @bantu ,
thanks for your comment/review.
You are right, the private key is not sent to the server, i will correct the README file.

@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch from 3ef8059 to 0fa5338 Compare August 24, 2020 13:30
README.md Outdated Show resolved Hide resolved
Copy link
Member

@ejoerns ejoerns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it looks like a good and relevant extension of the already-implemented authentication options for me.

I've also added some notes of what I've found while having a look on this.

We should also add some minimal tests for that (at least for option handling).

Please also note that the commit messages should be prefixed with the appropriate scope where applicable.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/config-file.c Outdated Show resolved Hide resolved
@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch 2 times, most recently from a0ab027 to 2df0ba8 Compare September 1, 2020 12:10
@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch from 2df0ba8 to 5bcc93c Compare September 14, 2020 11:01
@hongkongkiwi
Copy link

May I know when this is planned to be merged? It looks like all the needed changes are here?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@bantu
Copy link

bantu commented Feb 27, 2021

@hongkongkiwi It looks like this PR needs to be rebased (or merged) to resolve some conflicts.

I'd like to see this merged too. Anything in particular I can help with?

@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch from 5bcc93c to 986ab6b Compare March 1, 2021 12:31
@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch from 986ab6b to b327129 Compare April 29, 2021 13:38
@ctenruh-phytec
Copy link
Contributor Author

i noticed you removed the Authentication Methods from the README so i also removed my entry for the verification via certificates.
I applied all the changes requested, does it need anything else to be merged?

@Bastian-Krause
Copy link
Member

@ctenruh-phytec The authentication section from the README was moved to docs/using.rst with #74 (422d90d). Maybe add it there?

@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch 2 times, most recently from 83a2b0d to 9a1833b Compare April 30, 2021 13:25
@ctenruh-phytec ctenruh-phytec force-pushed the WIP/ctenruh-phytec/client_certificates branch 2 times, most recently from 14a5bb1 to e9a4e8b Compare April 30, 2021 13:37
@ctenruh-phytec
Copy link
Contributor Author

moved the description to docs/using.rst . Thanks @Bastian-Krause

Copy link
Member

@Bastian-Krause Bastian-Krause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need documentation for the new options in doc/reference.rst.

@@ -1,8 +1,8 @@
Using the RAUC hawkbit Updater
==============================

Authentication
--------------
Authentication via tokens
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Authentication via tokens
Authentication via Tokens

Comment on lines +38 to +55
- to have a TLS connection to the reverse proxy server
- to contain the client certificate
- to have the common name of the server certificate match the server
name set in the configuration file as "hawkbit_server"

The purpose of the reverse proxy is to:

- disband the TLS connection
- check if sent client certificate is valid
- extract the common name and fingerprint of the client certificate
- forward the common name and fingerprint as HTTP headers to the
hawkBit server

When the hawkBit server receives the request it checks if:

- sent common name matches with the controller ID of the target
- sent fingerprint(s) matches the expected fingerprint(s) which is set
in the system configuration settings of hawkBit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for indentation here.

Comment on lines +64 to +65
ssl = true
ssl_verify = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if these options are false?

Comment on lines +70 to +71
#client_cert = /path/to/client_certificate.pem
#client_key = /path/to/client_certificate.key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these options commented?

Comment on lines -275 to +271
g_set_error(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE,
"Neither auth_token nor gateway_token is set in the config.");
return NULL;
}
if (key_auth_token_exists && key_gateway_token_exists) {
g_info("Neither auth_token nor gateway_token is set, using client certificates");
key_client_cert_exists = get_key_string(ini_file, "client", "client_cert", &config->client_cert, NULL, NULL);
key_client_key_exists = get_key_string(ini_file, "client", "client_key", &config->client_key, NULL, NULL);
if (!key_client_cert_exists || !key_client_key_exists) {
g_set_error(error, 1, 4, "Neither a token nor client certificate are set!");
return NULL;
}
} else if (key_auth_token_exists && key_gateway_token_exists) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please read these config options outside of these if and then add checks for all combinations that are not allowed? This should make the logic simpler here.

Comment on lines +279 to +271

if (hawkbit_config->client_cert && hawkbit_config->client_key) {
curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_SSLCERT, hawkbit_config->client_cert);
curl_easy_setopt(curl, CURLOPT_SSLKEY, hawkbit_config->client_key);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in set_auth_curl_header() which is used for get_binary() as well as rest_request().

Comment on lines +392 to +384

if (hawkbit_config->client_cert && hawkbit_config->client_key) {
curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_SSLCERT, hawkbit_config->client_cert);
curl_easy_setopt(curl, CURLOPT_SSLKEY, hawkbit_config->client_key);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

echo 'Loading config file failed: Neither auth_token nor gateway_token is set in the config.' > expected_out &&
echo 'Loading config file failed: Neither a token nor client certificate are set!' > expected_out &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bash tests are gone since #83. It would be great to have an actual test case for this with a reverse proxy. We already use nginx for some test cases (see test/conftest.py).

Client certificate and privat key of Client certificate are send to the set
Server. Add description on how to use this authentication method in
"docs/using.rst" file.

Signed-off-by: Cem Tenruh <[email protected]>
@ejoerns ejoerns force-pushed the WIP/ctenruh-phytec/client_certificates branch from e9a4e8b to ed59577 Compare October 11, 2021 08:56
@ejoerns
Copy link
Member

ejoerns commented Oct 11, 2021

I've rebased this onto master now (no further modifications).

@ctenruh-phytec
Copy link
Contributor Author

@ejoerns thanks, i did not had the time to look into the requested changes, as i was busy with other tasks. I will try to work on this as soon as possible.

@ejoerns
Copy link
Member

ejoerns commented Oct 11, 2021

@ctenruh-phytec No worries, same here ;)

@Bastian-Krause
Copy link
Member

Superseded by #166.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs rework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants